package com.dty.system.service.impl;

import com.dty.model.base.ColumnModel;
import com.dty.system.mapper.ClickCommentMapper;
import com.dty.system.mapper.ColumnMapper;
import com.dty.system.service.ColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ColumnServiceImpl implements ColumnService {
    @Resource
    private ColumnMapper columnMapper;

    @Autowired
    private ClickCommentMapper clickCommentMapper;

    @Override
    public void addColumn(ColumnModel columnModel) {
        columnMapper.addColumn(columnModel);

    }

    @Override
    public Map selectColumn(ColumnModel columnModel) {
        Map map = new HashMap();

        //查询新闻
        List<ColumnModel> list= columnMapper.selectColumn(columnModel);
        //评论总数
        int count=clickCommentMapper.select(columnModel.getId());
        //点赞总数
 //       int clickCount=clickCommentMapper.selectClick(columnModel.getId());
//        for (ColumnModel model : list) {
//            model.setClickCount(String.valueOf(count));
//        }
        map.put("clickCount",count);
//        map.put("spotCount",clickCount);
        map.put("list",list);
        return map;
    }

    @Override
    public List<ColumnModel> showColumn(Integer whetherClick) {
        if (whetherClick==null){
            return null;
        }
        List<ColumnModel> list=columnMapper.showColumn(whetherClick);
        return list;
    }

    @Override
    public void offShelfColumn(Integer id,Integer offShelf) {
        columnMapper.offShelfColumn(id,offShelf);

    }

    @Override
    public void deleteColumn(Integer id) {
        columnMapper.deleteColumn(id);
    }

    @Override
    public void updateColumn(ColumnModel columnModel) {
        columnMapper.updateColumn(columnModel);
    }

    @Override
    public void addSpot(Integer id, Integer spot) {
        final ColumnModel column= new ColumnModel();
        ColumnModel columnModel= columnMapper.selectColumnById(id);
        if (spot==0 && columnModel.getSpot()!=0){
            column.setSpot(columnModel.getSpot()-1);
        }
        if (spot==1){
            column.setSpot(columnModel.getSpot()+1);
        }
        columnMapper.updateSpot(id,column.getSpot());
    }


}
